﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.ActiveRecord;
using System.Data;
using Xiaov.SmartWeb.Model;

namespace Xiaov.SmartWeb.Application.SysAdmin.Json
{
    public partial class Module : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Xiaov.SmartWeb.Model.ActiveRecord.S_PM_MODULE module = new S_PM_MODULE();
            List<Model.ActiveRecord.S_PM_MODULE> list =module.FindAllByCache().ToList();
            if (Request.QueryString["t"] == "treegrid")
            {
                string role = Request.QueryString["roleid"].ToRequestString();
                if(!string.IsNullOrEmpty(role))
                    list = module.ToCheckPermission(list, role);
                Response.Write(list.ToDataTable().SortBy("SORTBY", "ASC").ToJsonForTreeGrid("MODULEID", "PARENTMODULEID", "0"));
             
            }

            if (Request.QueryString["t"] == "combotree")
            {
                Response.Write(list.ToDataTable().SortBy("SORTBY", "ASC").ToJsonForComboTree("MODULEID", "MODULENAME", "PARENTMODULEID", "0", "", true));
            }

            if (Request.QueryString["t"] == "tree")
            {
                Response.Write(list.ToDataTable().SortBy("SORTBY", "ASC").ToJsonForTree("MODULEID", "MODULENAME", "PARENTMODULEID", "0", "MODULEURL"));
            }
            

            Response.End();
        }
    }
}